package com.example.mygrade.controller;

import com.example.mygrade.domain.TeacherMa;
import com.example.mygrade.intercepter.GlobalConstant;
import com.example.mygrade.service.StudentService;
import com.example.mygrade.service.TeacherMaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@Slf4j
public class StudentController {
    @Autowired
    TeacherMaService teacherMaService;

    @RequestMapping("/student/index")
    public String list(Model model, HttpServletRequest httprequest){
        // 获取session值
        HttpSession session = httprequest.getSession();

        // 跳转到教师页面
        if(session.getAttribute(GlobalConstant.TEACHER_SESSION_ID.getMsg()) != null){
            return "student/index";
        }
        // 跳转到学生页面
        if(session.getAttribute(GlobalConstant.USER_SESSION_ID.getMsg()) != null){
            return "student/myindex";
        }
        // 跳转到管理员页面
        if (session.getAttribute(GlobalConstant.MANAGE_SESSION_ID.getMsg()) != null){
            return "student/manage";
        }

        // 如果session值不存在则跳转到登录页
        return "redirect:/login/user";
//        List<TeacherMa> teacherMas = teacherMaService.findAll();
//        model.addAttribute("data",teacherMas);

    }
}
